package package03;

import java.util.Calendar;

/**
 * @Description Calendar的对象初始化、get(),add(),set()
 * @Author zzj
 * @Date 2020/7/15 13:48
 */
public class CalendarDemo01 {
    public static void main(String[] args) {
        // 获取对象
        Calendar calendar = Calendar.getInstance();  // 多态的形式

/*      // public int get(int field)：返回给定日历字段的值
        int year = calendar.get(Calendar.YEAR);
        int month = calendar.get(Calendar.MONTH) + 1; // 月份需要加上1
        int day = calendar.get(Calendar.DATE);  // 日是：Calendar.DATE
        System.out.println(year + "-" + month + "-" + day); // 2020-7-15*/

        // 查询前三年的今天
        // abstract public void add(int field, int amount);
       /* calendar.add(Calendar.YEAR, -3);
        int year = calendar.get(Calendar.YEAR);
        int month = calendar.get(Calendar.MONTH) + 1; // 月份需要加上1
        int day = calendar.get(Calendar.DATE);  // 日是：Calendar.DATE
        System.out.println(year + "-" + month + "-" + day); // 2017-7-15*/

        // 设置当前日历的年月日
        calendar.set(2048, 11, 11);
        int year = calendar.get(Calendar.YEAR);
        int month = calendar.get(Calendar.MONTH) + 1; // 月份需要加上1
        int day = calendar.get(Calendar.DATE);  // 日是：Calendar.DATE
        System.out.println(year + "-" + month + "-" + day); // 2048-12-11

    }
}
